<template>
  <div style="">
    <!-- <span style="color: #409EFF;margin-left: 10px">检验指标</span> -->
    <el-radio-group v-model="greenType" style="margin-left:15px " @change="changelaxy()">
      <el-radio-button v-if="!(this.$store.getters.hospitalId == 76 || this.$store.getters.hospitalId == 201)" label="胸痛" />
      <el-radio-button label="卒中" />
    </el-radio-group>
    <el-row style="margin-top: 10px;">
      <el-col :span="22" style="font-size: 14px;margin-left: 10px">
        检测范围指标类型管理:
        <el-select v-model="targetType" style="width: 15%;" filterable @change="selectList()">
          <el-option
            v-for="item in detection"
            :key="item.value"
            :value="item.value"
            :label="item.label"
          />
        </el-select>
      </el-col>
      <el-col :span="1">
        <el-button style="text-align: right" type="primary" @click="addimport()">新增/导入</el-button>
      </el-col>
    </el-row>
    <el-divider />
    <el-row>
      <el-col style="padding: 20px;">
        <el-table
          ref="multipleTable"
          :data="tableData"
          height="660"
          style="width: 100%; margin-top: -30px"
          class="table"
          border
        >
          <!--   <el-table-column
               type="selection"
               width="50"
               header-align="center"
               align="center">
             </el-table-column>-->
          <el-table-column
            label="检测名称"
            min-width="200"
            prop="checkName"
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="target"
            label="指标"
            min-width="200"
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="normalRangeStart"
            label="下限"
            min-width="200"
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="normalRangeEnd"
            label="上限"
            min-width="200"
            header-align="center"
            align="center"
          />
          <el-table-column
            label="操作"
            min-width="150"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              <el-button type="text" @click="details(scope.row)">详情</el-button>
              <el-button
                v-if="scope.row.defaultFlag !== '0'"
                type="text"
                style="color: red;margin-left: 30px"
                @click="handleDelete(scope.$index, scope.row)"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="float: right"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageTotal"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </el-col>
    </el-row>
    <!--新增指标弹出框-->
    <el-dialog
      v-el-drag-dialog
      title="新增指标"
      :visible.sync="newincalogase"
      width="85%"
      center
      style="margin-top: -70px;margin-left: 140px"
    >
      <el-form
        ref="send"
        :model="send"
        :rules="addbaserules"
        class="elform"
        style="width: 100%;border-bottom: 1px solid #F0F0EE;border-top: 1px solid #F0F0EE;height: 600px;overflow: auto"
      >
        <el-row style="margin-left: 10px">
          <el-col :span="6" style="margin-top: 10px;">
            <el-form-item label="检测范围指标类型管理:" prop="targetType">
              <el-select v-model="send.targetType" style="width:50%;" filterable>
                <el-option
                  v-for="item in detection"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="flag" :span="5">
            <el-form-item label="项目名称:" prop="projectName" style="margin-top: 10px;">
              <el-select
                v-model="send.projectName"
                style="width: 70%"
                filterable
                placeholder="请选择"
                @change="chaproname()"
              >
                <el-option
                  v-for="item in projectNametion"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="fleg" :span="5">
            <el-form-item label="项目名称:" prop="projectName" style="margin-top: 10px;">
              <el-select
                v-model="send.projectName"
                style="width: 70%"
                filterable
                placeholder="请选择"
                @change="chapronames()"
              >
                <el-option
                  v-for="item in projectNametions"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="检测样本:" prop="sample" style="margin-top: 10px;">
              <el-select v-model="send.sample" style="width: 55%" filterable>
                <el-option
                  v-for="item in tesamplection"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="flags" :span="5">
            <el-form-item label="检测名称:" prop="checkName" style="margin-top: 10px;">
              <el-select v-model="send.checkName" style="width: 60%" filterable placeholder="请选择检测名称">
                <el-option
                  v-for="item in namestction"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="flegs" :span="5">
            <el-form-item label="检测名称:" prop="checkName" style="margin-top: 10px;">
              <el-select v-model="send.checkName" style="width: 60%" filterable placeholder="请选择检测名称">
                <el-option
                  v-for="item in nametction"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" style="margin-top: 10px;">
            <el-button size="small" type="primary" @click="lead()">选择文件导入</el-button>
          </el-col>
          <el-col :span="2" style="margin-top: 10px;padding-left: 30px">
            <el-button size="small" type="primary" @click="Addindicators('send')">添加指标</el-button>
          </el-col>
        </el-row>
        <el-divider />
        <p v-for="(item, key) in tableDete" style="margin-left: 30px;font-size: 15px;margin-top: -10px">
          <el-row>
            <el-col :span="5" style="margin-left: -10px">
              <el-form-item label="指标类型:" prop="targetType">
                <el-select v-model="item.targetType" style="width:60%; margin-left: 17px" disabled>
                  <el-option
                    v-for="item in detection"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flag" :span="5">
              <el-form-item label="项目名称:" prop="projectName">
                <el-select v-model="item.projectName" style="width: 55%;margin-left: 30px" disabled>
                  <el-option
                    v-for="item in projectNametion"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="fleg" :span="5">
              <el-form-item label="项目名称:" prop="projectName">
                <el-select v-model="item.projectName" style="width: 55%;margin-left: 30px" disabled>
                  <el-option
                    v-for="item in projectNametions"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="检测样本:" prop="sample">
                <el-select v-model="item.sample" style="width:60%; margin-left: 25px" disabled>
                  <el-option
                    v-for="item in tesamplection"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flags" :span="5">
              <el-form-item label="检测名称:" prop="checkName">
                <el-select v-model="item.checkName" style="width: 60%;margin-left: 24px" disabled>
                  <el-option
                    v-for="item in namestction"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flegs" :span="5">
              <el-form-item label="检测名称:" prop="checkName">
                <el-select v-model="item.checkName" style="width: 60%;margin-left: 24px" disabled>
                  <el-option
                    v-for="item in nametction"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4" style="text-align: right">
              <el-button type="text" style="color: red;font-size: 16px;" @click="remove(item,key)">删除
              </el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="指标:" prop="target">
                <el-input v-model="item.target" style="width:50%;margin-left: 45px" disabled/>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="正常参考范围:" prop="normalRangeStart">
                <el-input v-model="item.normalRangeStart" style="width:35%;" />
              </el-form-item>
            </el-col>
            <el-col :span="2" style="margin-left: 4px">
              <el-form-item label="~" prop="normalRangeEnd">
                <el-input v-model="item.normalRangeEnd" style="width:60%;margin-left: -5px" />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="使用状态:" prop="status">
                <el-select v-model="item.status" style="width: 60%;margin-left: 20px" filterable>
                  <el-option
                    v-for="item in methodction"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item v-if="flagsS" label="单位:" prop="content">
                <el-select v-model="item.content" style="width: 60%;margin-left: 20px" filterable>
                  <el-option
                    v-for="(item,index) in companyList"
                    :key="index"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item v-if="flegsS" label="单位:" prop="content">
                <el-select v-model="item.content" style="width: 60%;margin-left: 20px" filterable>
                  <el-option
                    v-for="(item,index) in companysList"
                    :key="index"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="临床意义:" prop="significance">
                <el-input
                  v-model="item.significance"
                  type="textarea"
                  :rows="4"
                  style="width: 92%;margin-left: 16px"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="偏差:" prop="deviation">
                <el-input v-model="item.deviation" style="width: 92%;margin-left: 45px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="检测时间:" prop="testTime">
                <el-input v-model="item.testTime" style="width: 60%;margin-left: 15px" />
                <!-- <el-date-picker
                  v-model="item.testTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  style="width:60%;margin-left: 17px"
                  placeholder="选择日期"
                /> -->
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="样本量:" prop="sampleSize">
                <el-input v-model="item.sampleSize" style="width:60%;margin-left:40px" />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="采血管:" prop="blood">
                <el-input v-model="item.blood" style="width:60%;margin-left:40px" />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="采血管(可用):" prop="availableBlood">
                <el-input v-model="item.availableBlood" style="width:60%;margin-left:0px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider />
        </p>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button
          style="width: 65px;height: 40px;line-height: 30px;padding: 0px 5px;margin-left: 0px"
          @click="cancle"
        >取消</el-button>
        <el-button
          type="primary"
          style="width: 65px;height: 40px;line-height: 30px;padding: 0px 5px;margin-left: 100px"
          @click="addTypeData('send')"
        >保存</el-button>
      </span>
    </el-dialog>
    <!--编辑指标弹出框-->
    <el-dialog
      v-el-drag-dialog
      title="编辑指标"
      :visible.sync="edindicators"
      width="83%"
      center
      style="margin-top: -70px;margin-left: 140px"
    >
      <el-form
        ref="editupdata"
        :model="editupdata"
        class="elform"
        style="width: 100%;border-bottom: 1px solid #F0F0EE;border-top: 1px solid #F0F0EE;height: 350px;overflow: auto"
      >
        <p v-for="(item,key) in tableDoto" style="margin-left: 30px;font-size: 15px;">
          <el-row>
            <el-col :span="5">
              <el-form-item label="指标类型:" prop="targetType">
                <el-select v-model="item.targetType" style="width:60%; margin-left: 17px" disabled>
                  <el-option
                    v-for="item in detection"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flag" :span="5">
              <el-form-item label="项目名称:" prop="projectName">
                <el-select v-model="item.projectName" style="width: 55%;margin-left: 27px" disabled>
                  <el-option
                    v-for="item in projectNametion"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="fleg" :span="5">
              <el-form-item label="项目名称:" prop="projectName">
                <el-select v-model="item.projectName" style="width: 55%;margin-left: 27px" disabled>
                  <el-option
                    v-for="item in projectNametions"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="检测样本:" prop="sample">
                <el-select v-model="item.sample" style="width:60%; margin-left: 25px" disabled>
                  <el-option
                    v-for="item in tesamplection"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flags" :span="5">
              <el-form-item label="检测名称:" prop="checkName">
                <el-select v-model="item.checkName" style="width: 60%;margin-left: 24px" disabled>
                  <el-option
                    v-for="item in namestction"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flegs" :span="5">
              <el-form-item label="检测名称:" prop="checkName">
                <el-select v-model="item.checkName" style="width: 60%;margin-left: 24px" disabled>
                  <el-option
                    v-for="item in nametction"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="指标:" prop="target">
                <el-input v-model="item.target" style="width:60%;margin-left: 45px" disabled/>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="正常参考范围:" prop="normalRangeStart">
                <el-input v-model="item.normalRangeStart" style="width:35%;" />
              </el-form-item>
            </el-col>
            <el-col :span="2" style="margin-left: 4px">
              <el-form-item label="~" prop="normalRangeEnd">
                <el-input v-model="item.normalRangeEnd" style="width:60%;margin-left: -5px" />
              </el-form-item>
            </el-col>
            <el-col v-if="item.defaultFlag === '1'" :span="5">
              <el-form-item label="使用状态:" prop="status">
                <el-select v-model="item.status" style="width: 60%;margin-left: 20px" filterable>
                  <el-option
                    v-for="item in methodction"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="item.defaultFlag === '0'" :span="5">
              <el-form-item label="使用状态:" prop="status">
                <el-select v-model="item.status" disabled style="width: 60%;margin-left: 20px" filterable>
                  <el-option
                    v-for="item in methodction"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flagsS" :span="5">
              <el-form-item label="单位:" prop="content">
                <el-select v-model="item.content" style="width: 60%;margin-left: 20px" filterable>
                  <el-option
                    v-for="(item,index) in companyList"
                    :key="index"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="flegsS" :span="5">
              <el-form-item label="单位:" prop="content">
                <el-select v-model="item.content" style="width: 60%;margin-left: 20px" filterable>
                  <el-option
                    v-for="(item,index) in companysList"
                    :key="index"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="临床意义:" prop="significance">
                <el-input
                  v-model="item.significance"
                  type="textarea"
                  :rows="4"
                  style="width: 92%;margin-left: 16px"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="偏差:" prop="deviation">
                <el-input v-model="item.deviation" style="width: 92%;margin-left: 45px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="检测时间:" prop="testTime">
                <el-input v-model="item.testTime" style="width: 60%;margin-left: 15px" />
                <!-- <el-date-picker
                  v-model="item.testTime"
                  type="date"
                  style="width:60%;margin-left: 17px"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                /> -->
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="样本量:" prop="sampleSize">
                <el-input v-model="item.sampleSize" style="width:60%;margin-left:40px" />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="采血管:" prop="blood">
                <el-input v-model="item.blood" style="width:60%;margin-left:40px" />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="采血管(可用):" prop="availableBlood">
                <el-input v-model="item.availableBlood" style="width:60%;margin-left:0px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-divider />
        </p>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button
          style="width: 60px;height: 30px;line-height: 20px;padding: 0px 5px;margin-left: 20px"
          @click="upcancle"
        >取消</el-button>
        <el-button
          type="primary"
          style="width: 60px;height: 30px;line-height: 20px;padding: 0px 5px;margin-left: 100px"
          @click="upTypeData('editupdata')"
        >保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script type="text/javascript">
import { saveList, selectList, deleteList, getChangeOnUse, getAllOnUseTesttarget, getUnit} from '@/api/back-management/Test_indicators'
import elDragDialog from '@/directive/el-drag-dialog'
export default {
  name: 'TestIndicators',
  directives: { elDragDialog },
  data() {
    return {
      disabled: false,
      /* 项目名称*/
      flag: true,
      fleg: false,
      /* 检测名称*/
      flags: true,
      flegs: false,
      /* 单位 */
      flagsS: true,
      flegsS: false,
      /* 胸痛卒中单选按钮*/
      greenType: (this.$store.getters.hospitalId == '76' || this.$store.getters.hospitalId == '201') ? '卒中' : '胸痛',
      /* 范围指标*/
      targetType: '默认',
      detection: [{
        value: '默认',
        label: '默认'
      }, {
        value: '设备-岚煜LS2000',
        label: '设备-岚煜LS2000'
      }, {
        value: '设备-Icare2000',
        label: '设备-Icare2000'
      }],
      /* 指标 */
      targetData: [],
      /* 单位 */
      companyList: [],
      companysList: [],
      tableDete: [],
      /* 下方表格数据*/
      tableData: [],
      /* 表格分页参数*/
      currentPage: 1,
      pagesize: 10,
      pageTotal: 0,
      /* 新增/导入弹出框*/
      newincalogase: false,
      /* 胸痛项目名称*/
      projectNametion: [{
        value: '生物标志物',
        label: '生物标志物'
      }, {
        value: '凝血功能',
        label: '凝血功能'
      }, {
        value: '血常规',
        label: '血常规'
      }, {
        value: '血生化',
        label: '血生化'
      }],
      /* 卒中项目名称*/
      projectNametions: [{
        value: '血糖',
        label: '血糖'
      }, {
        value: '血脂四项',
        label: '血脂四项'
      }, {
        value: '凝血功能',
        label: '凝血功能'
      }, {
        value: '血常规',
        label: '血常规'
      }, {
        value: '肾功能及电解质',
        label: '肾功能及电解质'
      }, {
        value: '其他',
        label: '其他'
      }],
      /* 检测样本*/
      tesamplection: [{
        value: '全血',
        label: '全血'
      }, {
        value: '血清',
        label: '血清'
      }, {
        value: '尿液',
        label: '尿液'
      },
      {
        value: '粪便',
        label: '粪便'
      }
      ],
      /* 胸痛检测名称*/
      namestction: [
        {
          value: 'N-端脑利钠肽前体',
          label: 'N-端脑利钠肽前体'
        }, {
          value: '肌钙蛋白I',
          label: '肌钙蛋白I'
        }, {
          value: '肌钙蛋白T',
          label: '肌钙蛋白T'
        },
        {
          value: '肌酸激酶同工酶',
          label: '肌酸激酶同工酶'
        },
        {
          value: '肌红蛋白',
          label: '肌红蛋白'
        },
        {
          value: 'D-二聚体',
          label: 'D-二聚体'
        },
        {
          value: '脑钠肽',
          label: '脑钠肽'
        },
        {
          value: '凝血酶原时间',
          label: '凝血酶原时间'
        },
        {
          value: '活化部分凝血活酶',
          label: '活化部分凝血活酶'
        },
        {
          value: '凝血酶时间',
          label: '凝血酶时间'
        },
        {
          value: '纤维蛋白原',
          label: '纤维蛋白原'
        },
        {
          value: '国际标准化比值',
          label: '国际标准化比值'
        },
        {
          value: '血小板计数',
          label: '血小板计数'
        },
        {
          value: '红细胞计数',
          label: '红细胞计数'
        },
        {
          value: '白细胞',
          label: '白细胞'
        },
        {
          value: '中性杆状核粒细胞',
          label: '中性杆状核粒细胞'
        },
        {
          value: '血红蛋白',
          label: '血红蛋白'
        },
        {
          value: '中性杆状核粒细胞(x10/L)',
          label: '中性杆状核粒细胞(x10/L)'
        },
        {
          value: '中性分叶核粒细胞',
          label: '中性分叶核粒细胞'
        },
        {
          value: '中性分叶核粒细胞(x10/L)',
          label: '中性分叶核粒细胞(x10/L)'
        },
        {
          value: '嗜酸粒细胞',
          label: '嗜酸粒细胞'
        },
        {
          value: '嗜酸粒细胞(x10/L)',
          label: '嗜酸粒细胞(x10/L)'
        },
        {
          value: '嗜碱粒细胞',
          label: '嗜碱粒细胞'
        }, {
          value: '嗜碱粒细胞(x10/L)',
          label: '嗜碱粒细胞(x10/L)'
        }, {
          value: '淋巴细胞',
          label: '淋巴细胞'
        }, {
          value: '淋巴细胞(x10/L)',
          label: '淋巴细胞(x10/L)'
        }, {
          value: '单核细胞',
          label: '单核细胞'
        }, {
          value: '单核细胞(x10/L)',
          label: '单核细胞(x10/L)'
        }, {
          value: '肌酐',
          label: '肌酐'
        }],
      /* 卒中检测名称*/
      nametction: [
        {
          value: '血糖',
          label: '血糖'
        }, {
          value: '甘油三酯',
          label: '甘油三酯'
        }, {
          value: '胆固醇',
          label: '胆固醇'
        },
        {
          value: '低密度脂蛋白胆固醇',
          label: '低密度脂蛋白胆固醇'
        },
        {
          value: '高密度脂蛋白胆固醇',
          label: '高密度脂蛋白胆固醇'
        },
        {
          value: '凝血酶原时间',
          label: '凝血酶原时间'
        },
        {
          value: '活化部分凝血活酶',
          label: '活化部分凝血活酶'
        },
        {
          value: '凝血酶时间',
          label: '凝血酶时间'
        },
        {
          value: '纤维蛋白原',
          label: '纤维蛋白原'
        },
        {
          value: '国际标准化比值',
          label: '国际标准化比值'
        },
        {
          value: '血小板计数',
          label: '血小板计数'
        }, {
          value: '红细胞计数',
          label: '红细胞计数'
        }, {
          value: '白细胞计数',
          label: '白细胞计数'
        }, {
          value: '白细胞分类计数',
          label: '白细胞分类计数'
        }, {
          value: '血红蛋白',
          label: '血红蛋白'
        }, {
          value: '血清肌酐',
          label: '血清肌酐'
        }, {
          value: '血清尿素氮',
          label: '血清尿素氮'
        }, {
          value: '尿酸',
          label: '尿酸'
        }, {
          value: '钾',
          label: '钾'
        },
        {
          value: '钠',
          label: '钠'
        },
        {
          value: '氯',
          label: '氯'
        },
        {
          value: '钙',
          label: '钙'
        }, {
          value: '无机磷',
          label: '无机磷'
        }, {
          value: '镁',
          label: '镁'
        }, {
          value: '肌钙蛋白',
          label: '肌钙蛋白'
        }, {
          value: '同型半胱氨酸',
          label: '同型半胱氨酸'
        }
      ],
      /* 使用状态*/
      methodction: [{
        value: '1',
        label: '使用'
      }, {
        value: '0',
        label: '禁用'
      }],
      /* 新增弹出框表单*/
      send: {
        targetType: '默认',
        projectName: '',
        sample: '',
        checkName: ''
      },
      /* 新增弹出框规则*/
      addbaserules: {
        targetType: [{
          required: true,
          message: '请选择检测范围指标',
          trigger: '[blur,change]'
        }],
        projectName: [{
          required: true,
          message: '请输入项目名称',
          trigger: '[blur,change]'
        }],
        sample: [{
          required: true,
          message: '请输入检测样本',
          trigger: '[blur,change]'
        }],
        checkName: [{
          required: true,
          message: '请输入名称',
          trigger: '[blur,change]'
        }]
      },
      /* 编辑弹出框*/
      edindicators: false,
      /* 编辑弹出框表单*/
      editupdata: {
        targetType: '默认',
        projectName: '',
        sample: ''
      },
      /* 详情指标*/
      tableDoto: [],
      /* 删除数组*/
      delist: []
    }
  },
  mounted() {
    this.selectList()
  },
  methods: {

    /* 新增项目名称与检测名称联动*/
    chaproname() {
      this.send.checkName = ''
      if (this.send.projectName == '生物标志物') {
        this.namestction = [
          {
            value: 'N-端脑利钠肽前体',
            label: 'N-端脑利钠肽前体'
          }, {
            value: '肌钙蛋白I',
            label: '肌钙蛋白I'
          }, {
            value: '肌钙蛋白T',
            label: '肌钙蛋白T'
          },
          {
            value: '肌酸激酶同工酶',
            label: '肌酸激酶同工酶'
          },
          {
            value: '肌红蛋白',
            label: '肌红蛋白'
          },
          {
            value: 'D-二聚体',
            label: 'D-二聚体'
          },
          {
            value: '脑钠肽',
            label: '脑钠肽'
          }
        ]
      } else if (this.send.projectName == '凝血功能') {
        this.namestction = [
          {
            value: '凝血酶原时间',
            label: '凝血酶原时间'
          },
          {
            value: '活化部分凝血活酶',
            label: '活化部分凝血活酶'
          },
          {
            value: '凝血酶时间',
            label: '凝血酶时间'
          },
          {
            value: '纤维蛋白原',
            label: '纤维蛋白原'
          },
          {
            value: '国际标准化比值',
            label: '国际标准化比值'
          }]
      } else if (this.send.projectName == '血常规') {
        this.namestction = [
          {
            value: '血小板计数',
            label: '血小板计数'
          }, {
            value: '红细胞计数',
            label: '红细胞计数'
          }, {
            value: '白细胞',
            label: '白细胞'
          }, {
            value: '中性杆状核粒细胞',
            label: '中性杆状核粒细胞'
          }, {
            value: '血红蛋白',
            label: '血红蛋白'
          },{
            value: '中性杆状核粒细胞(x10/L)',
            label: '中性杆状核粒细胞(x10/L)'
          }, {
            value: '中性分叶核粒细胞',
            label: '中性分叶核粒细胞'
          }, {
            value: '中性分叶核粒细胞(x10/L)',
            label: '中性分叶核粒细胞(x10/L)'
          }, {
            value: '嗜酸粒细胞',
            label: '嗜酸粒细胞'
          }, {
            value: '嗜酸粒细胞(x10/L)',
            label: '嗜酸粒细胞(x10/L)'
          }, {
            value: '嗜碱粒细胞',
            label: '嗜碱粒细胞'
          }, {
            value: '嗜碱粒细胞(x10/L)',
            label: '嗜碱粒细胞(x10/L)'
          }, {
            value: '淋巴细胞',
            label: '淋巴细胞'
          }, {
            value: '淋巴细胞(x10/L)',
            label: '淋巴细胞(x10/L)'
          }, {
            value: '单核细胞',
            label: '单核细胞'
          }, {
            value: '单核细胞(x10/L)',
            label: '单核细胞(x10/L)'
          }]
      } else if (this.send.projectName == '血生化') {
        this.namestction = [
          {
            value: '肌酐',
            label: '肌酐'
          }]
      }
    },
    chapronames() {
      this.send.checkName = ''
      if (this.send.projectName == '血糖') {
        this.nametction = [
          {
            value: '血糖',
            label: '血糖'
          }
        ]
      } else if (this.send.projectName == '血脂四项') {
        this.nametction = [
          {
            value: '甘油三酯',
            label: '甘油三酯'
          }, {
            value: '胆固醇',
            label: '胆固醇'
          },
          {
            value: '低密度脂蛋白胆固醇',
            label: '低密度脂蛋白胆固醇'
          },
          {
            value: '高密度脂蛋白胆固醇',
            label: '高密度脂蛋白胆固醇'
          }
        ]
      } else if (this.send.projectName == '凝血功能') {
        this.nametction = [
          {
            value: '凝血酶原时间',
            label: '凝血酶原时间'
          },
          {
            value: '活化部分凝血活酶',
            label: '活化部分凝血活酶'
          },
          {
            value: '凝血酶时间',
            label: '凝血酶时间'
          },
          {
            value: '纤维蛋白原',
            label: '纤维蛋白原'
          },
          {
            value: '国际标准化比值',
            label: '国际标准化比值'
          }
        ]
      } else if (this.send.projectName == '血常规') {
        this.nametction = [
          {
            value: '红细胞计数',
            label: '红细胞计数'
          }, {
            value: '白细胞计数',
            label: '白细胞计数'
          }, {
            value: '白细胞分类计数',
            label: '白细胞分类计数'
          }, {
            value: '血红蛋白',
            label: '血红蛋白'
          }, {
            value: '血小板计数',
            label: '血小板计数'
          }
        ]
      } else if (this.send.projectName == '肾功能及电解质') {
        this.nametction = [
          {
            value: '血清肌酐',
            label: '血清肌酐'
          }, {
            value: '血清尿素氮',
            label: '血清尿素氮'
          }, {
            value: '尿酸',
            label: '尿酸'
          }, {
            value: '钾',
            label: '钾'
          },
          {
            value: '钠',
            label: '钠'
          },
          {
            value: '氯',
            label: '氯'
          },
          {
            value: '钙',
            label: '钙'
          }, {
            value: '无机磷',
            label: '无机磷'
          }, {
            value: '镁',
            label: '镁'
          }
        ]
      } else if (this.send.projectName == '其他') {
        this.nametction = [
          {
            value: '肌钙蛋白',
            label: '肌钙蛋白'
          }, {
            value: '同型半胱氨酸',
            label: '同型半胱氨酸'
          }
        ]
      }
    },

    /* 胸痛/卒中单选按钮改变方法*/
    changelaxy() {
      if (this.greenType == '胸痛') {
        this.selectList()
        this.flag = true
        this.fleg = false
        this.flags = true
        this.flegs = false
        this.flagsS = true
        this.flegsS = false
      } else if (this.greenType == '卒中') {
        this.selectList()
        this.flag = false
        this.fleg = true
        this.flags = false
        this.flegs = true
        this.flagsS = false
        this.flegsS = true
      }
      this.tableDete = []
      this.send.targetType = '默认'
      this.send.projectName = ''
      this.send.checkName = ''
      this.send.sample = ''
    },
    /* 新增/导入*/
    addimport() {
      this.newincalogase = true
    },
    /* 取消弹出框*/
    cancle() {
      this.newincalogase = false
    },
    /* 新增保存*/
    addTypeData(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          for (let i = 0; i < this.tableDete.length; i++) {
            this.tableDete[i].greenType = this.greenType
            this.tableDete[i].hospitalId = this.$store.getters.hospitalId
          }
          const data = this.tableDete
          let rules = true
          for (let i = 0; i < data.length; i++) {
            if (data[i].target === '') {
              this.$message({
                type: 'error',
                message: '指标必须选择!'
              })
              rules = false
              break
            } else if (data[i].normalRangeStart === '' && data[i].normalRangeEnd === '') {
              this.$message({
                type: 'error',
                message: '范围不能都为空!'
              })
              rules = false
              break
            } else if (data[i].content === '') {
              this.$message({
                type: 'error',
                message: '单位不能为空!'
              })
              rules = false
              break
            }
          }
          if (!rules) {
            return false
          }
          // 保存
          saveList(data).then(res => {
            if (res.code === 9999) {
              this.$message({
                type: 'error',
                message: '新增失败!'
              })
            } else {
              this.$message({
                type: 'success',
                message: '新增成功!'
              })
              this.newincalogase = false
              this.tableDete = []
              this.send.targetType = '默认'
              this.send.projectName = ''
              this.send.sample = ''
              this.send.checkName = ''
              this.selectList()
            }
          })
          // 状态变化
        } else {
          this.$message({
            message: '添加失败',
            type: 'error',
            customClass: 'zZindex'
          })
        }
      })
    },
    /* 弹出框内部导入*/
    lead() {
      alert('暂时无导入')
    },
    /* 新增弹出框添加指标*/
    Addindicators(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          this.companyList = []
          this.companysList = []
          const obj = {
            status: '1',
            target: '',
            normalRangeStart: '',
            normalRangeEnd: '',
            content:''
          }
          obj.targetType = this.send.targetType
          obj.projectName = this.send.projectName
          obj.sample = this.send.sample
          obj.checkName = this.send.checkName
          for (let i = 0; i < this.targetData.length; i++) {
            if (this.targetData[i].checkName === this.send.checkName) {
              obj.target = this.targetData[i].target
              this.tableDete.push(obj)
              if (this.greenType === '胸痛') {
                getUnit({ target: this.targetData[i].target, greenType: this.greenType }).then(res => {
                  if (res.code === 0) {
                    if (res.data !== null) {
                      let arr = res.data.unit.split(',')
                      arr.forEach(item => {
                        this.companyList.push({
                          value: item,
                          label: item
                        })
                      })
                    }
                  } else {
                    this.companyList = []
                  }
                })
              } else if (this.greenType === '卒中') {
                getUnit({ target: this.targetData[i].target, greenType: this.greenType }).then(res => {
                  if (res.code === 0) {
                    if (res.data !== null) {
                      let arrStroke = res.data.unit.split(',')
                      arrStroke.forEach(item => {
                        this.companysList.push({
                          value: item,
                          label: item
                        })
                      })
                    }
                  } else {
                    this.companysList = []
                  }
                })
              }
            }
          }
        } else {
          this.$message({
            message: '添加失败',
            type: 'error',
            customClass: 'zZindex'
          })
        }
      })
    },
    /* 新增弹出框删除指标*/
    remove(data, val) {
      this.tableDete.splice(val, 1)
    },
    /* 详情*/
    details(row) {
      this.tableDoto = []
      this.companyList = []
      this.companysList = []
      getUnit({ target: row.target, greenType: this.greenType }).then(res => {
        if (res.code === 0) {
          if (res.data.greenType === '胸痛') {
            if (res.data.unit !== null) {
              let arr = res.data.unit.split(',')
              arr.forEach(item => {
                this.companyList.push({
                  value: item,
                  label: item
                })
              })
            }
          } else {
            if (res.data.unit !== null) {
              let arr = res.data.unit.split(',')
              arr.forEach(item => {
                this.companysList.push({
                  value: item,
                  label: item
                })
              })
            }
          }
        } else {
          this.companyList = []
          this.companysList = []
        }
      })
      this.tableDoto.push(row)
      this.edindicators = true
      if (row.status === '1') {
        this.disabled = true
      } else {
        this.disabled = false
      }
    },
    /* 删除*/
    handleDelete(index, row) {
      this.$confirm('确认删除本条数据？')
        .then(_ => {
          this.delist = []
          this.delist.push(row.id)
          const data = this.delist
          deleteList(data).then(res => {
            if (res.code === 9999) {
              this.$message({
                type: 'error',
                message: '删除失败!'
              })
            } else {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
              this.selectList()
            }
          })
          // done()
        })
        .catch(_ => {})
    },
    /* 编辑弹出框取消*/
    upcancle() {
      this.selectList()
      this.edindicators = false
    },
    /* 编辑弹出框确认保存*/
    upTypeData(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          const data = this.tableDoto
          console.log(data, 'data')
          if (data[0].normalRangeStart === '' && data[0].normalRangeEnd === '') {
            this.$message({
              type: 'error',
              message: '范围不能都为空!'
            })
          } else if (data[0].content === null) {
            this.$message({
              type: 'error',
              message: '单位不能为空!'
            })
          } else if (data[0].defaultFlag === '0') {
            this.$message({
              type: 'error',
              message: '默认数据不能修改!'
            })
          } else {
            // 保存
            saveList(data).then(res => {
              if (res.code === 9999) {
                this.$message({
                  type: 'error',
                  message: '修改失败!'
                })
              } else {
                this.$message({
                  type: 'success',
                  message: '修改成功!'
                })
                this.edindicators = false
                this.selectList()
              }
            })
          }

        } else {
          this.$message({
            message: '添加失败',
            type: 'error',
            customClass: 'zZindex'
          })
        }
      })
    },
    /* 查询表格*/
    selectList() {
      const data = {
        pageNum: this.currentPage,
        pageSize: this.pagesize,
        targetType: this.targetType,
        greenType: this.greenType,
        hospitalId: this.$store.getters.hospitalId,
        checkName: ''
      }
      selectList(data).then(res => {
        this.tableData = res.data
        this.pageTotal = Number(res.total)
      })
      getAllOnUseTesttarget({greenType:this.greenType,hospitalId: this.$store.getters.hospitalId}).then(res => {
        let data = res.data
        this.targetData = data
      })
    },
    // 分页尺寸改变
    handleSizeChange(size) {
      this.pagesize = size
      this.selectList()
    },
    // 分页换页
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage
      this.selectList()
    }
  }

}
</script>
<style scoped>
.table /deep/ th:first-child .cell, .el-table--border td:first-child .cell {
    padding-left: 7px;
  }

  .elform /deep/ .el-form-item {
    margin-bottom: 8px;
  }

  .elform /deep/ .el-form-item__error {
    margin-left: 85px;
  }
</style>
